/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.kramerius.fedoraaccess.metadataUpdate.datastream;

import cz.mzk.rehan.commons.DatastreamId;
import cz.mzk.kramerius.fedoraaccess.FedoraConnector;
import org.dom4j.Document;

/**
 *
 * @author Martin Řehánek <rehan at mzk.cz>
 */
    public abstract class InlineXmlDatastreamUpdater extends DatastreamUpdater {

    public InlineXmlDatastreamUpdater(FedoraConnector con, DatastreamId dsId) {
        super(con, dsId);
    }

    @Override
    public void updateDatastream(String pid) throws Exception {
        Document originalDs = con.getXmlDatastreamDissemination(pid, dsId);
        if (originalDs == null) {
            throw new Exception("No datastream " + dsId.toString() + " found for object " + pid);
        }
        Document updatedDoc = updateDatastreamDoc(originalDs);
        boolean updated = con.updateDatastreamInlineContent(pid, dsId, updatedDoc);
        if (!updated) {
            throw new Exception("Failed to update datastream " + dsId.toString() + " of object " + pid);
        }
    }

    abstract public Document updateDatastreamDoc(Document originalDs);
}
